package com.sharein.auth.actions;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sharein.auth.beans.User;
import com.sharein.auth.business.UserManager;

public class Signup implements Action{

	@Override
	public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException{
		String fullname, shareinID, password, email, gender;
		boolean male;
		fullname = request.getParameter("fullname");
		shareinID = request.getParameter("new_shareinID");
		password = request.getParameter("new_password");
		email = request.getParameter("email");
		gender = request.getParameter("gender");
		if(gender.equals("male")) male = true;
		else male = false;
		String question = request.getParameter("question");
		String answer = request.getParameter("answer");
		UserManager.signUpUser(new User(shareinID, password, email, fullname, male), question, answer);
		HttpSession session = request.getSession();
		session.setAttribute("shareinID", shareinID);
		UserManager.setUserSignedIn(shareinID, true);
		response.sendRedirect("home.html");
		return true;
	}

}